package org.example.im.common.util;

import lombok.experimental.UtilityClass;

import java.security.SecureRandom;
import java.util.Objects;

/**
 * @author dingrui
 * @since 2022/2/10
 * @description
 */
@UtilityClass
public class EnumUtil {

    private static final SecureRandom RANDOM = new SecureRandom();

    public <T extends Enum<?>> T random(Class<T> clazz) {
        T[] enums = clazz.getEnumConstants();
        if (Objects.isNull(enums) || enums.length == 0) return null;
        int r = RANDOM.nextInt(enums.length);
        return enums[r];
    }
}
